<template>
    <van-button><van-uploader :after-read="upload">导入</van-uploader></van-button>
      <van-button @click="add">导出</van-button>
 
      <van-button type="primary" text="增加" @click="show = true" />
      <van-overlay :show="show" @click="show = false">
  <div class="wrapper" @click.stop>
           <input type="text" v-model="name"><br/>
      <input type="text" v-model="code"><br/>
      <input type="text" v-model="pid"><br/>
      <button @click="add1">添加</button>
    <div/>
  </div>
</van-overlay>

      <left/>
</template>

<script>
import left from "../com/left.vue"
import axios from "axios"
export default {
    components:{ left},
data(){
    return{
                    show: false,
            name:"",
            code:"",
            pid:""
    }
},methods:{
            upload(file){
            let formData = new FormData()
            formData.append('file',file.file)
            console.log(formData);
            axios({url:"http://127.0.0.1:5000/upload",method:'post',data:formData}).then(res=>{
                console.log(res);
            })
 
        },
        add(){
            axios({url:"http://127.0.0.1:5000/download",methods:"post"}).then(res=>{
                console.log(res);
            })
        },
        add1(){
            if(this.name==""){
                alert("请输入公司名称")
            }location.reload()
            if(this.code==""){
                alert("请输入公司编号")
            }location.reload()
            if(this.pid==""){
                alert("请输入所属编号")
            }location.reload()
            let datas = new FormData()
            datas.append("name",this.name)
            datas.append("code",this.code)
            datas.append("pid",this.pid)
            console.log(datas);
            axios({url:"http://127.0.0.1:5000/adddept",method:"post",data:datas}).then(res=>{
                if (res.data.code == 200){
                    alert("添加成功")
                    location.reload()
                }
                
            })
        }
}
}
</script>

<style>
  .wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
  }
</style>